package com.Work;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

import static java.lang.System.out;

public class Exam02 {
    public static void main(String[] args) {
        // 定义输入文件夹路径和输出文件夹路径
        String inputFolderPath = "E:\\IO流练习\\OutPutStream\\current";
        String outputFolderPath = "E:\\IO流练习\\OutPutStream\\new2\\1.mp4";

        // 获取输入文件夹中的所有文件
        File inputFolder = new File(inputFolderPath);
        File[] files = inputFolder.listFiles();

        // 创建线程列表
        List<Thread> threads = new ArrayList<>();

        // 遍历文件列表，为每个文件创建一个线程进行处理
        for (File file : files) {
            if (file.isFile()) {
                Thread thread = new Thread(new FileProcessor(file,outputFolderPath));
                threads.add(thread);
                thread.start();
            }
        }

        // 等待所有线程完成
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        out.println("所有文件处理完成！");
    }
}

class FileProcessor implements Runnable {
    private File inputFile;
    private String outputFolderPath;

    public FileProcessor(File inputFile, String outputFolderPath) {
        this.inputFile = inputFile;
        this.outputFolderPath = outputFolderPath;
    }

    @Override
    public void run() {
        // 读取文件，进行处理
        try (FileInputStream in = new FileInputStream(inputFile);
             FileOutputStream out = new FileOutputStream(outputFolderPath,true)) {
            byte[] buff = in.readAllBytes();
            out.write(buff);
            System.out.println("文件处理完成：" + inputFile.getName());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

